package com.visionet.waveletData.web.repository.account;

import java.util.List;

import javax.persistence.QueryHint;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import com.visionet.waveletData.web.entity.account.User;
import com.visionet.waveletData.web.entity.business.UserInfo;

public interface UserDaoPlus  extends Repository<User, Long>{
	
//	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
//	public User findByLoginName(String userName);
	
//	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
//	public User findByLoginNameAndOrgId(String loginName, Long orgId);
//    @QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
//    public List<User> findByAliasNameAndOrgId(String aliasName, Long orgId);
	
//	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
//	@Query("select u.id from User u inner join u.roleList r where u.isLock=0 and u.orgId = ?2 and r.name in (?1) order by u.id ")
//	List<Long> findAllUserWithRole(List<String> roleIds,Long orgId);
//	
//	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
//	@Query("select u.id,u.aliasName,u.userInfo.firstLetter,u.userInfo.email " +
//			"from User u inner join u.roleList r " +
//			"where u.isLock=0 and u.orgId = :orgId and r.name in (:roleIds) " +
//			"and (u.userInfo.firstLetter like %:userName% " +
//			"	or u.userInfo.userName like %:userName% " +
//			"	or u.userInfo.email like %:userName% ) " +
//			"order by u.userInfo.firstLetter,u.id ")
//	public List<Object[]> findUsersWithRoleAndUserName(
//			@Param("roleIds") List<String> roleIds,
//			@Param("userName") String userName, @Param("orgId") Long orgId);
//	
//	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
//	@Query("select u.id,u.aliasName,u.userInfo.firstLetter,u.userInfo.email,'U' " +
//			" from User u inner join u.roleList r " +
//			"where u.isLock=0 and u.orgId = ?4 and r.name in (?1) " +
//			" and (u.userInfo.firstLetter like %?2% " +
//			"	or u.userInfo.userName like %?3% ) " +
//			" order by u.userInfo.firstLetter,u.id ")
//	public List<Object[]> findUserByNameOrTeamOrMail(List<String> roleIds,
//			String firstLetter, String userName, Long orgId);
//	
//	
//	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
//	@Query("select u.id,u.userInfo.trueName,u.userInfo.trueFirstLetter,u.aliasName,u.orgName,u.userInfo.departmentId " +
//			"from User u inner join u.roleList r " +
//			" where u.isLock=0 and u.orgId = ?2 and r.name in (?1) " +
//			" and (u.userInfo.trueFirstLetter like %?3% or u.userInfo.trueName like %?3% ) ")
//	List<Object[]> searchTrueNameUser(List<String> roleIds,Long orgId,String userName);
//
//    @QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
//    @Query("select u.id,u.userInfo.trueName,u.userInfo.trueFirstLetter,u.aliasName " +
//            "from User u inner join u.roleList r " +
//            " where u.isLock=0 and u.orgId = ?3 and u.userInfo.departmentId= ?2 and r.name in (?1) " +
//            " and (u.userInfo.trueFirstLetter like %?4% or u.userInfo.trueName like %?4% ) ")
//    List<Object[]> searchTrueNameUser(List<String> roleIds,Long deptId,Long orgId,String userName);
//
//    @QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
//    @Query("select u.id,u.userName,u.firstLetter,u.departmentId " +
//            "from UserInfo u, Relationship r where u.id = r.otherUserId and r.userId= ?1 and u.isLock=0 " +
//            " and (u.userName like %?2% or u.firstLetter like %?2%) order by u.userName")
//    List<Object[]> findAttentionList(Long currentUserId, String userName, Pageable page);
//
//    @QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
//    @Query("select u.id,u.userName,u.firstLetter,u.departmentId " +
//            "from UserInfo u where u.orgId= ?1 and u.isLock=0 " +
//            " and (u.userName like %?2% or u.firstLetter like %?2%) order by u.userName")
//    List<Object[]> findAllByAliasName(Long orgId, String userName, Pageable page);


}
